package com.sheep.jucdemo.part6.part6_1;

import java.util.concurrent.locks.LockSupport;

/**
 * @Date 2022/4/18 22:06
 * @Created by sheep
 */
public class Test6_1_1_2 {

    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("第1次 child thread begin park!");
                LockSupport.park();
                System.out.println("第1次 child thread return!");
                System.out.println("第2次 child thread begin park!");
                LockSupport.park();
                //LockSupport.parkNanos(10000);
                System.out.println("第2次 child thread return!");
            }
        });
        // 启动子线程
        thread.start();
        //  main线程休眠1s 确保子线程执行完LockSupport.park()后再执行LockSupport.unpark(thread)方法
        Thread.sleep(1000);
        System.out.println("main thread begin unpark");
        // 调用unpark方法让thread线程持有关联LockSupport类的许可证，然后park方法返回
        LockSupport.unpark(thread);

    }
}
